#!/bin/bash

#########
# COLORS
#########

#colors
#colors
white="\033[1;37m"                                          ##
grey="\033[0;37m"                                           ##
purple="\033[1;35m"                                         ##
red="\033[1;31m"                                            ##
green="\033[1;32m"                                          ##
yellow="\033[1;33m"                                         ##
purple="\033[0;35m"                                         ##
cyan="\033[0;36m"                                           ##
cyan1="\033[1;36m"                                          ##
cafe="\033[0;33m"                                           ##
fiuscha="\033[0;35m"                                        ##
blue="\033[1;34m"                                           ##
l_red="\033[1;37;41m"                                       ##
nc="\033[0m"                                                ## 

arch=`uname -m`

#spinner
spinner() {
        pid=$!
        spin='\|/-'
        i=0
        tput civis
        while kill -0 $pid 2>/dev/null
	do
                i=$(( (i+1) %4 ))
                printf "\r${cyan1}[${spin:$i:1}]${nc} ${cyan1} $launch"
                sleep .1
	done
        printf "\r   ${green}[✔]${nc} ${green} $splashdown";echo
        tput cnorm
}

function os () {
	cat /etc/os-release > /dev/null 2>&1
	if [ "$?" -eq "0" ]; then
		OS=DEBIAN 
		BIN="/usr/bin"
		main="/usr/share/shark"			
	else
		OS=TERMUX
		BIN="${PREFIX}/bin"
		main="${PREFIX}/share/shark"
	fi
}

function git_clone() {
	launch="cloning shark";splashdown="shark cloned";echo
	[ -d "${main}" ] && rm -rf ${main} > /dev/null 2>&1
	(git clone https://github.com/Bhaviktutorials/shark --quiet ${main}) & spinner
}


function dependencies() {
        launch="installing lib";splashdown="installed lib";echo
	for i in apache2 php jq curl wget; do		
		if [ ! -f "${BIN}/${i}" ]; then			
    			if [ ${OS} != "DEBIAN" ]; then			        
    				(apt-get install ncurses-utils ${i} -y > /dev/null 2&>1) & spinner
			else
				(sudo apt-get install ${i} -y > /dev/null 2&>1) & spinner
			fi
		fi
	done
}


function setup_ngrok() {
	if [ ! -f  "${BIN}/ngrok" ]; then
		if [[ ("$arch" == *'arm'*) || ("$arch" == *'Android'*) ]]; then
			ngrok_url="https://github.com/Linux-Droid/Ngrok/raw/master/Ngrok_Linux_Droid.zip"
		elif [[ "$arch" == *'aarch64'* ]]; then
			ngrok_url="https://github.com/Linux-Droid/Ngrok/raw/master/Ngrok_Linux_Droid.zip"
		elif [[ "$arch" == *'x86_64'* ]]; then
			ngrok_url="https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip"
		else
			ngrok_url="https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-386.zip"
		fi
		launch="installing ngrok";splashdown="installed ngrok";echo
		(wget --quiet ${ngrok_url} -O ngrok.zip) & spinner
		unzip -q ngrok.zip && rm -rf ngrok.zip && chmod +x ngrok && mv ngrok $BIN
	fi
}

function final_touchup() {
	for i in shark; do
		chmod +x ${main}/${i}
		mv ${main}/${i} ${BIN}
		printf "\n${green}>>${white} simply run : shark \n\n ${nc}"
	done
}

os
git_clone
dependencies
setup_ngrok
final_touchup

#####################################
#       DON'T TRY TO COPY 😂😂     #
#   JUST LEARNING KEEP SUPPORTING   #
#             THANKYOU              #
#####################################
